<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/11/11
  Time: 19:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>公告发布</title>
    <style type="text/css" rel="stylesheet">
        body{
            font-family: "楷体";
            font-size: 16px;
        }
        .all{
            width: 850px;
            max-height: 550px;
            overflow: auto;
            border: 2px solid red;
            margin: 0 auto;
            padding: 50px 30px;
            box-sizing: border-box;
            margin-top: 25px;
        }
        .yheader,.all1{
            font-size: 18px;
            font-weight: 600;
            color: #a39933;
            margin-bottom: 10px;
        }
        table{
            width: 600px;
            margin: 0 auto;
        }
        td{
            text-align: center;
        }
        button{
            height: 25px;
            background: #a39933;
            cursor: pointer;
            border: none;
            margin-right: 10px;
            color: #fff;
        }
    </style>
    <script src="/WebContent/JQuery/jquery-3.4.1.js" type="text/javascript"></script>
</head>
<body>
<article class="all">
    <div class="yheader">当前位置&nbsp;&gt;&gt;&nbsp;查询公告&nbsp;&gt;&gt;&nbsp;<a href="/WebContent/HTML/AdminPage/admin_state/fbgonggao.jsp" class="fbgg">发布新公告</a></div>
    <div class="all1"></div>
    <div id="text" style="box-sizing: border-box;padding: 10px;width: 600px;margin: 0 auto;border:2px solid red;display: none">

    </div>
</article>
<script>
    $(document).ready(function () {
        $.ajax({
            url:"/SuperAdminServlet?type=ggcx",
            dataType:"json",
            async:true,
            type:"get",
            success:function (data) {
                collback(data);
            },
            error:function (error) {
                alert("请求失败！");

            }
        })
        var collback = function (data) {
            var id = data.stateId;
            var cont = data.stateContent;
            var date = data.stateTime;
            var time = "2020年"+date.month+"月"+date.date+"日 "+date.hours+":"+date.minutes+":"+date.seconds;
            var $table = $("<table border='1'></table>");
            $table.appendTo(".all1");
            $("<tr></tr>").append("<th>发布者</th>").append("<th>发布时间</th>").append("<th>操作</th>").appendTo($table);
            var $tr = $("<tr></tr>");
            $tr.appendTo($table);
            $("<td></td>").html(data.adminUsername).appendTo($tr);
            $("<td></td>").html(time).appendTo($tr);
            $("<td></td>").html("<button id='btn1'>查看</button><button id='btn2'>删除</button>").appendTo($tr);
            $("#btn1").click(function () {
                $("#text").css("display","block").html(cont);
            })
            $("#btn2").click(function () {
                if(confirm("确认删除该公告？")){
                    $.ajax({
                        url:"/SuperAdminServlet?type=ggsc",
                        data:"id="+id,
                        dataType: "text",
                        type: "get",
                        success:function (data) {
                            if(data == "1"){
                                alert("删除成功！");
                                window.location.reload();
                            }else if(data == "0"){
                                alert("删除失败！");
                            }
                        },
                        error:function (error) {

                            alert("请求失败！")
                        }
                    })
                }else
                    return false;
            })
        }

    })
</script>
</body>
</html>
